package net.wanho.shop.controller;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.shop.po.PermissionApi;
import net.wanho.shop.service.PermissionApiService;
import net.wanho.shop.vo.AjaxResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;


/**
 * <p>
 * 权限功能表 前端控制器
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Api(tags = "权限功能表接口")
@RestController
@RequestMapping("/permission-api")
@RequiredArgsConstructor
public class PermissionApiController {

    private final PermissionApiService permissionApiService;

    @ApiOperation("权限功能表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pagenum, @ApiParam("页大小") @RequestParam(defaultValue = "5") int pagesize, @ApiParam("查询条件") PermissionApi permissionApi) {
        PageInfo<PermissionApi> pageInfo = permissionApiService.findPage(pagenum, pagesize, permissionApi);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询权限功能表")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Serializable id) {
        return AjaxResult.success(permissionApiService.findById(id));
    }

    @ApiOperation("新增权限功能表")
    @PostMapping
    public AjaxResult add(@RequestBody PermissionApi permissionApi) {
        permissionApiService.add(permissionApi);
        return AjaxResult.success();
    }

    @ApiOperation("修改权限功能表")
    @PutMapping
    public AjaxResult modify(@RequestBody PermissionApi permissionApi) {
        permissionApiService.modify(permissionApi);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除权限功能表")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Serializable id) {
        permissionApiService.removeById(id);
        return AjaxResult.success();
    }

}
